package com.lyf.task.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lyf.task.dao.ProductMapper;
import com.lyf.task.dao.TradeMapper;
import com.lyf.task.dao.UserMapper;
import com.lyf.task.domain.Product;
import com.lyf.task.domain.Trade;
import com.lyf.task.domain.User;
import com.lyf.task.service.TradeService;

@Service
public class TradeServiceImpl implements TradeService {

	@Autowired
	private TradeMapper tradeMapper;
	@Autowired
	private UserMapper userMapper;
	@Autowired
	private ProductMapper productMapper;

	@Override
	public List<Trade> getAllTrade() {
		// TODO Auto-generated method stub

		return tradeMapper.getAllTrade();
	}

	@Override
	public int insertTrade(Trade trade) {
		// TODO Auto-generated method stub

		int result = tradeMapper.insertTrade(trade);
		return result;
	}

	@Override
	public List<Trade> getAllTradeByPid(int pid) {

		List<Trade> list = tradeMapper.getAllTradeByPid(pid);
		for (Trade trade : list) {
			User user = new User();
			user.setUid(trade.getUid());
			User user2 = userMapper.getUserByUid(user);
			trade.setUser(user2);
			Product product = productMapper.getProductById(pid + "");
			trade.setProduct(product);

		}
		return list;
	}

}
